package com.epoint.mobile.demo.tab;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperTabView;
import com.epoint.mobileoa.tools.ToastHelp;

/**
 * @author liyc
 * @time 2012-12-27 下午4:11:10
 * @annotation 示例程序
 */
public class TestTabView extends SuperTabView {

	private EditText etFill1;
	private Button uv_bt;
	MyHandler myHandler;

	@Override
	public void initControls(){
		super.initControls();
		myHandler = new MyHandler();

//		MyThread m = new MyThread();
//		new Thread(m).start();


		//hideTopBar();


		View llzw = inflate(R.layout.testlayout1, null);
		View llfj = inflate(R.layout.updateview, null);
		View llbz = inflate(R.layout.backup, null);
		View llzzz = inflate(R.layout.epoint_addfeiyongbaoxiaoview, null);
		View test = inflate(R.layout.epoint_drfy, null);
		View test2 = inflate(R.layout.epoint_addnewworkcontentviewmission, null);
		uv_bt = (Button) llfj.findViewById(R.id.uv_bt);
		uv_bt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				/*etFill1.setText(etFill1.getText()+""+uv_bt.getText());
				showTabViewByIndex(0);
				int a = 1/0;
				System.out.println(a);*/
				int a = 1/0;
				System.out.println(a);
				/* AlertHelp.ShowAlert(getContext(),
						 tm.getDeviceId()
						 +"\n"+android.os.Build.MODEL
						 +"\n"+android.os.Build.BRAND
						 +"\n"+android.os.Build.MANUFACTURER
						 +"\n"+android.os.Build.VERSION.SDK
						 +"\n"+android.os.Build.VERSION.INCREMENTAL
						 +"\n"+android.os.Build.VERSION.CODENAME
						 +"\n"+android.os.Build.PRODUCT
						 +"\n"+android.os.Build.HOST
						 +"\n"+android.os.Build.VERSION.SDK_INT
						 );*/
				//				 AlertHelp.ShowAlert(getContext(),
				//						 "设备ID："+tm.getDeviceId()
				//						 +"\n手机型号："+android.os.Build.MANUFACTURER+"-"+android.os.Build.MODEL
				//						 +"\n系统版本号："+android.os.Build.VERSION.SDK_INT
				//						 );
			}
		});


		etFill1 = (EditText) llzw.findViewById(R.id.etFill1);
		addTabInfo(
				new String[]{"正文","附件","备注","扩展","测试","学习"}, 
				new View[]{llzw,llfj,llbz,llzzz,test,test2}
				);

		//		addTabInfo(
		//				new String[]{"正文","附件","备注","扩展"}, 
		//				new View[]{llzw,llfj,llbz,llzzz}
		//				);

		//		addTabInfo(new String[]{"正文","附件"}, new View[]{llzw,llfj});
	}

	@Override
	public String setTitle() {
		return "邮件详情";
	}

	@Override
	public int initTask(int index) {
		switch (index) {
		case 0:
			ToastHelp.showAndroidToastWorning(this, "正文TAB");
			new GetServerTimeNewTask(this, 1, null, "",2);
			break;
		case 1:
			ToastHelp.showAndroidToastWorning(this, "附件TAB");
			break;
		case 2:
			ToastHelp.showAndroidToastWorning(this, "备注TAB");
			break;
		case 5:
			new TestReflectInvokeTask(this, 5, null, null, 2);
			break;
		default:
			break;
		}
		return super.initTask(index);
	}

	@Override
	public void refreshForNewTask(int TaskId, Object... param){
		switch (TaskId) {
		case 1:
			etFill1.setText(param[0].toString());
			break;
		case 5:
			Toast.makeText(this, param[0].toString(), Toast.LENGTH_LONG).show();
			break;
		default:
			break;
		}
	}

	@Override
	public int getLayoutInt() {
		return R.layout.supertabview_left;
	}
	@Override
	public int[] getTabButtonDrawable() {
		return new int[]{R.drawable.btn1,R.drawable.btn2};
	}

	class MyHandler extends Handler
	{
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			Bundle b = msg.getData();
			String ayMessage = b.getString("ayMessage");
			Toast.makeText(getContext(), ayMessage, Toast.LENGTH_SHORT).show();
		}

	}

	class MyThread implements Runnable{

		@Override
		public void run() {
			int n = 365;
			while(true){
				Message msg = Message.obtain();
				Bundle b = new Bundle();
				b.putString("ayMessage", "奥运倒计时"+n+"天");
				msg.setData(b);
				myHandler.sendMessage(msg); 
				n--;
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}

	} 
}
